var aFunc = {
	plusReady: function() {
		if (mui.os.plus) {
			plus.navigator.closeSplashscreen();
			plus.screen.lockOrientation("portrait-primary");
			plus.navigator.setStatusBarBackground(common.colour.statusBackground);
			aVariable.webview.current = plus.webview.currentWebview();
		}

		aVariable.webview.current.setStyle({
			bounce: "vertical",
			bounceBackground: common.colour.pageBackground,
		});

		if (mui.os.ios) {
			var webView = plus.webview.currentWebview().nativeInstanceObject();
			webView.plusCallMethod({
				"setKeyboardDisplayRequiresUserAction": true
			});
		}


		aFunc.bindEvent();
		//页面内容跟随键盘弹起
		// aFunc.initNativeObjects();
		// aFunc.showSoftInput();
	},

	bindEvent: function() {

		mui('.mui-bar-nav').on("tap", 'button', function() {
			
		});

		//监听手机号码的输入
		aVariable.ipt.account.addEventListener("input", function(value) {
			var iphoneNum = this.value;
			if (util.isPoneAvailable(iphoneNum)) {
				aVariable.view.warnIcon.style.display = "none";
			} else {
				aVariable.view.warnIcon.style.display = "";
			}
			if (this.value.length == 0) {
				aVariable.view.warnIcon.style.display = "none";
			}
		});



		aVariable.btn.accountLoginBtn.addEventListener('tap', function(event) {

			console.log("点击了登录");
			aVariable.ipt.account.blur();
			aVariable.ipt.userName.blur();
			var iphone = aVariable.ipt.account.value;
			var username = aVariable.ipt.userName.value;
			var company = aVariable.ipt.company.value;
			var department = aVariable.ipt.department.value;
			
			if (iphone.length == 0) {
				util.ToastTitle("请输手机号码");
				return;
			}
			var ifiphone = util.isPoneAvailable(iphone);
			if (!ifiphone) {
				util.ToastTitle("请输入正确的手机号");
				return;
			}
			
			if (username.length == 0) {
				util.ToastTitle("请输入姓名");
				return;
			}
			if (company.length == 0) {
				util.ToastTitle("请输入公司名称");
				return;
			}
			if (department.length == 0) {
				util.ToastTitle("请输入部门");
				return;
			}
			var _this = this;
			aFunc.requestLogin(iphone, username, company,department, _this);

		});

	},

	enterPage: function(data) {
		setTimeout(function() {
			plus.webview.close(aVariable.webview.current, "none", 0);
		}, 1500);
	},

	initNativeObjects: function() {
		if (mui.os.android) {
			var main = plus.android.runtimeMainActivity();
			var Context = plus.android.importClass("android.content.Context");
			aVariable.InputMethodManager = plus.android.importClass(
				"android.view.inputmethod.InputMethodManager");
			aVariable.imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
		} else {
			aVariable.nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
		}
	},
	showSoftInput: function() {
		if (mui.os.android) {
			aVariable.imm.toggleSoftInput(0, aVariable.InputMethodManager.SHOW_FORCED);
		} else {
			aVariable.nativeWebview.plusCallMethod({
				"setKeyboardDisplayRequiresUserAction": false
			});
		}
	},

	//请求登录的方法
	requestLogin: function(iphone, username, company,department, _this) {
		mui(_this).button('loading');
		loginServer.register(iphone, username, company,department,function(data) {
			mui(_this).button('reset');
			if (data.code == 0) {
				util.ToastTitle("注册成功");
				setTimeout(function(){
					mui.back();
				},1000);
			} else {
				util.ToastTitle(data.msg);
			}
		}, function(error) {
			mui(_this).button('reset');
			if (error != null) {
				if (JSON.stringify(error).length == 0) {
					util.ToastTitle("请求注册失败");
					return;
				}
				util.ToastTitle(JSON.parse(error).msg);
			} else {
				util.ToastTitle("请求注册失败");
			}
		});
	}

};
